package com.jnevision.util;

import java.util.Base64;

import org.springframework.web.multipart.MultipartFile;

public class Base64Util {

	public static MultipartFile base64ToMultipart(String base64) {
		String[] baseStrs = base64.split(",");

		Base64.Decoder decode = Base64.getDecoder();

		byte[] content = decode.decode(baseStrs[1]);

		for (int i = 0; i < content.length; ++i) {
			if (content[i] < 0) {
				content[i] += 256;
			}
		}

		String header = baseStrs[0];

		return new BASE64DecodedMultipartFile(content, header);
	}
}
